package com.ssm.stu.service.impl;

import com.ssm.stu.controller.Code;
import com.ssm.stu.dao.MajorDao;
import com.ssm.stu.exception.BusinessException;
import com.ssm.stu.exception.SystemException;
import com.ssm.stu.pojo.Major;
import com.ssm.stu.service.MajorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class MajorServiceImpl implements MajorService {
    @Autowired
    private MajorDao majorDao;

    @Override
    public boolean insertMajor(Major major) {
        return majorDao.insertMajor(major) > 0;
    }

    @Override
    public boolean updateMajor(Major major) {
        return majorDao.updateMajor(major) > 0;
    }

    @Override
    public boolean deleteMajor(String  id) {
        return majorDao.deleteMajor(id) > 0;
    }

    @Override
    public Major selectMajorById(String  id) {
        if (id.equals("01")){
            throw new BusinessException(Code.BUSINESS_ERR,"输入的数据有误");
        }
        return majorDao.selectMajorById(id) ;
    }

    @Override
    public List<Major> selectAllMajor() {
        try {
            int i = 1/0;
        }catch (Exception e){
            throw new SystemException(Code.SYSTEM_ERR,"数据有误");
        }
        return majorDao.selectAllMajor();
    }
}
